/**
 * img lazy load
 * @author thon
 * @date 
 */

define(function (require, exports) {
	var $ = require('jquery');
	(function($) {
		$.imglazy = function(){
	 
	        $('img.lazy').each(function(){
	            var distanceToTop = $(this).offset().top;
	            var scroll = $(window).scrollTop();
	            var windowHeight = $(window).height();
	            var isVisible = distanceToTop - scroll < windowHeight;
	            if (isVisible) {
	                $(this).attr('src', $(this).attr('data-src')).removeClass('lazy');
	            }
	        });
	 
	    };
	 
	    $(function(){
	        $(window).scroll(function() {
	        	$.imglazy();
	        });
	    });
	 
	})(jQuery);
});